// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import 'babel-polyfill'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import $ from 'jquery'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap/dist/js/bootstrap.min'
// import "./assets/font-icon/iconfont.css";
Vue.use(ElementUI)
Vue.config.productionTip = false;
Vue.prototype.$axios =axios;

Vue.prototype.getCookie = function (name) {
    // return 1;
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) {
        // console.log(arr);
        return unescape(arr[2]);
    }
    else
        return null;
}

Vue.prototype.setCookie = function (cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    var domain = null;
    if (/\.com$/i.test(location.host)) {
        domain = location.host.replace(/^[^\.]*\./i, '.');
    }
    var expires = "expires=" + d.toUTCString();
    document.cookie = cname + "=" + (cvalue) + "; " + expires + (domain ? ";domain=" + domain : '') + ";path=/";
}

Vue.prototype.configHeader = function (method) {
    return method == 'get' ? {
        headers: {
            'token': this.getCookie("token"),
            //'userName': this.getCookie('userName')
        }
    } 
    : 
    {
        headers: {
            "Content-Type": "application/x-www-form-urlencoded",
            'token': this.getCookie("token"),
            //'userName': this.getCookie('userName')
        }
    }
}

//设置请求头
axios.defaults.headers.post["Content-type"] = "application/json"
// axios.defaults.baseURL = 'http://192.168.0.135';
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
  data:{
    eventBus: new Vue()
  }
})
